<style lang="scss" scoped>
</style>

<template>
  <div>我的消息</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { request } from '../../axios/request'

// 获取userId, sessionId
const userId = ref(JSON.parse(localStorage.getItem('userId') as string) || '')
const sessionId = ref(JSON.parse(localStorage.getItem('sessionId') as string) || '')

// 系统消息
const systemMsg = ref([])
const getsystem = async () => {
  await request
    .get('/api/health/user/verify/v1/findSystemNoticeList', {
      params: {
        page: 1,
        count: 10
      },
      headers: {
        userId: userId.value,
        sessionId: sessionId.value
      }
    })
    .then((res) => {
      console.log(res.data)
      systemMsg.value = res.data
      console.log(systemMsg.value)
    })
}
getsystem()

// 问诊消息
const inqMsg = ref([])
const getInq = async () => {
  await request
    .get('/api/health/user/verify/v1/findInquiryNoticeList', {
      params: {
        page: 1,
        count: 10
      },
      headers: {
        userId: userId.value as number,
        sessionId: sessionId.value as string
      }
    })
    .then((res) => {
      console.log(res.data)
      inqMsg.value = res.data
      console.log(inqMsg.value)
    })
}
getInq()

// H币入账消息
const HcoinMsg = ref([])
const getHcoin = async () => {
  await request
    .get('/api/health/user/verify/v1/findHealthyCurrencyNoticeList', {
      params: {
        page: 1,
        count: 10
      },
      headers: {
        userId: userId.value as number,
        sessionId: sessionId.value as string
      }
    })
    .then((res) => {
      console.log(res.data)
      HcoinMsg.value = res.data
      console.log(HcoinMsg.value)
    })
}
getHcoin()

// 未读消息条数
const unreadMsg = ref(0)
const getUnread = async () => {
    await request.get('/api/health/user/verify/v1/findUserNoticeReadNum', {
        headers: {
            userId: userId.value as number,
            sessionId: sessionId.value as string
        }
    }).then((res) => {
        console.log(res.data)
        unreadMsg.value = res.data
        console.log(unreadMsg.value)
    })
}
getUnread()

// 一键清空未读消息
const clearMsg = async () => {
    await request.put('/api/health/user/verify/v1/modifyAllStatus', {
        headers: {
            userId: userId.value as number,
            sessionId: sessionId.value as string
        }
    }).then((res) => {
        console.log(res.data)
        unreadMsg.value = 0
        console.log(unreadMsg.value)
    })
}
</script>